﻿using KD.Service.HR.Utility;
using Logistics.Model;
using Logistics.Model.QueryModel;
using Logistics.Service;
using Logistics.WebApi.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;

namespace Logistics.WebApi.Controllers
{
     [MyAuthority]
    public class BidDisputeController : ApiController
    {
         private BidBaseService bidService = new BidBaseService();
         private CompanyService companyService = new CompanyService();
         private BidDisputeService biddisputeService = new BidDisputeService();
        /// <summary>
        /// 查询标单页面
        /// </summary>
        /// <param name="bidbase"></param>
        /// <returns></returns>
        [HttpPost]
         public ResponseModel GetBidList(BidQuery query)
        {
            var resultmod = new ResponseModel();
            try
            {
                //获取校验token的accountid
                var accountId = Convert.ToInt32(HttpContext.Current.Request.Headers[LogisticsConst.LOGIN_HEADER]);
                if (accountId != null)
                {
                    int company_id = companyService.GetCompanyIdByAccountId(accountId);
                    query = query ?? new BidQuery();
                    resultmod.mod = biddisputeService.GelBidList(company_id, query.page - 1, query.pagesize);
                    resultmod.InitResultState(GetDataStateEnum.Success);
                }
                else
                {
                    resultmod.InitResultState(LoginEnum.Error04);
                }

            }
            catch (Exception ex)
            {
                resultmod.InitResultState(ex);
            }
            return resultmod;
        }

        /// <summary>
        /// 查询标单页面
        /// </summary>
        /// <param name="bidbase"></param>
        /// <returns></returns>
        [HttpPost]
        public ResponseModel GelBidDisputeList(BidQuery query)
        {
            var resultmod = new ResponseModel();
            try
            {
                //获取校验token的accountid
                var accountId = Convert.ToInt32(HttpContext.Current.Request.Headers[LogisticsConst.LOGIN_HEADER]);
                if (accountId != null)
                {
                    int company_id = companyService.GetCompanyIdByAccountId(accountId);
                    query = query ?? new BidQuery();
                    resultmod.mod = biddisputeService.GelBidDisputeList(company_id, query.page - 1, query.pagesize);
                    resultmod.InitResultState(GetDataStateEnum.Success);
                }
                else
                {
                    resultmod.InitResultState(LoginEnum.Error04);
                }

            }
            catch (Exception ex)
            {
                resultmod.InitResultState(ex);
            }
            return resultmod;
        }

         [HttpPost]
         public ResponseModel AddComment(wuliu_wlcompany_comment mod)
        {
             var resultmod = new ResponseModel();
             try
             {
                 var accountId = Convert.ToInt32(HttpContext.Current.Request.Headers[LogisticsConst.LOGIN_HEADER]);
                 var company = companyService.GetCompanyByAccountId(accountId);
                 mod.company_id = company.company_id;
                 mod.company_name = company.company_name;
                 mod.company_no = company.company_no;
                 var num = biddisputeService.AddComment(mod);
                 resultmod.InitResultState(GetDataStateEnum.Success);
             }
             catch (Exception ex)
             {
                 resultmod.InitResultState(ex);
             }
            return resultmod;
        }

        [HttpPost]
        /// <summary>
        /// 投诉调解申请
        /// </summary>
        /// <param name="apply"></param>
        /// <returns></returns>
        public ResponseModel Apply(wuliu_bid_dispute apply)
        {
            var resultmod = new ResponseModel();
            try
            {
                var num = biddisputeService.BidDisputeAdd(apply);
                if (num > 0)
                    resultmod.InitResultState(StateEnum.Success);
                else
                    resultmod.InitResultState(StateEnum.Error);
            }
            catch (Exception ex)
            {
                resultmod.InitResultState(ex);
            }
            return resultmod;
        }
         /// <summary>
         /// 获取详情
         /// </summary>
         /// <param name="id"></param>
         /// <returns></returns>
          [HttpPost]
         public ResponseModel Get(int id)
        {
            var resultmod = new ResponseModel();
              try
              {
                  resultmod.mod = biddisputeService.BidDisputeGet(id);
                  resultmod.InitResultState(StateEnum.Success);
              }
              catch (Exception ex)
              {
                  resultmod.InitResultState(ex);
              }
            return resultmod;

        }
    }
}